﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TimbreRecognition.Recognition.Model.Kohenen;

namespace TimbreRecognition.Recognition.Teacher.Kohenen
{
    public abstract class AbstractKohenenTeacher : IKohenenTeacher {

        protected double getDistance(KohenenNeuron neuron1, KohenenNeuron neuron2){
            int xDistance = neuron1.getX() - neuron2.getX();
            int yDistance = neuron1.getY() - neuron2.getY();
            return Math.Sqrt(Math.Pow(xDistance, 2) + Math.Pow(yDistance, 2));
        }

        protected double getError(KohenenNetwork network, double[] input){

            KohenenNeuron neuron = network.getWinner();
            double[] weights = neuron.getWeights();
            double error = 0;
            for (int  i = 0; i < input.Length; i++){
                double inputValue = input[i];
                double weight = weights[i];
                error += Math.Abs(inputValue - weight);
            }

            return error;
        }

        public abstract void teach(KohenenNetwork network, List<double[]> data);

        public abstract void SetLogger(ILogger logger);
    }
}
